package xby.study.annotations.util;

import org.springframework.core.annotation.AliasFor;
import org.springframework.core.annotation.AnnotatedElementUtils;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Set;

public class TestMergedAnnotation {
    public static void main(String[] args) {



        Animal animal = AnnotatedElementUtils.getMergedAnnotation(XBY.class, Animal.class);
        System.out.println(animal);

        System.out.println("----------");

        Set<Animal> animals = AnnotatedElementUtils.getAllMergedAnnotations(XBY.class, Animal.class);
        System.out.println(animals.size());
        for(Animal a: animals){
            System.out.println(a);
        }

//        Animal animal1 = AnnotatedElementUtils.findMergedAnnotation(XBY.class, Animal.class);
//        System.out.println(animal1);


    }
}



@Tiger2(tigerName2="CNM2")
@Tiger(tigerName = "CNM")
class XBY {

}






@Retention(RetentionPolicy.RUNTIME)
@Cat
@interface Tiger {


    @AliasFor(annotation = Cat.class, attribute = "catName")
    String tigerName() default "tigerName";

    @AliasFor(annotation = Cat.class, attribute = "catAge")
    String tigerAge() default "tigerAge";

}

@Retention(RetentionPolicy.RUNTIME)
@Cat2
@interface Tiger2 {


    @AliasFor(annotation = Cat2.class, attribute = "catName2")
    String tigerName2() default "tigerName2";

    @AliasFor(annotation = Cat2.class, attribute = "catAge2")
    String tigerAge2() default "tigerAge2";

}






@Retention(RetentionPolicy.RUNTIME)
@Animal
@interface Cat {

    @AliasFor(attribute = "name" ,annotation = Animal.class)
    String catName() default "catName";

    @AliasFor(attribute = "age" ,annotation = Animal.class)
    String catAge() default "catAge";

}

@Retention(RetentionPolicy.RUNTIME)
@Animal
@interface Cat2 {

    @AliasFor(attribute = "name" ,annotation = Animal.class)
    String catName2() default "catName2";

    @AliasFor(attribute = "age" ,annotation = Animal.class)
    String catAge2() default "catAge2";

}


@Retention(RetentionPolicy.RUNTIME)
@interface Animal{

   // @AliasFor(attribute = "age")
    String name() default "Animal-name";


    //@AliasFor(attribute = "name")
    String age() default "Animal-age";

}



